package com.tequila.core.service.impl;

import com.google.common.collect.Lists;

import com.tequila.core.dao.BranchStoreDao;
import com.tequila.core.service.BranchStoreService;
import com.tequila.domain.dto.BranchStoreDto;
import com.tequila.domain.entity.BranchStore;
import com.tequila.domain.query.BranchStoreQuery;

import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class BranchStoreServiceImpl implements BranchStoreService {
    public static final Logger logger = LoggerFactory.getLogger(BranchStoreServiceImpl.class);

    @Resource
    private BranchStoreDao branchSotreDao;

    @Override
    public Pagination<BranchStoreDto> queryPageListByParam(BranchStoreQuery query) {
        Assert.assertNotNull(query);
        int total = branchSotreDao.queryPageCountByParam(query);

        List<BranchStoreDto> list = Lists.newArrayList();
        if (total > 0) {
            list = branchSotreDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public BranchStoreDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        BranchStore branchSotre = branchSotreDao.queryById(id);
        BranchStoreDto branchStoreDto = new BranchStoreDto();
        BeanHelper.copyProperties(branchStoreDto,branchSotre);
        return branchStoreDto;
    }

    @Override
    public List<BranchStoreDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return branchSotreDao.queryByIdList(idList);
    }

    @Override
    public List<BranchStoreDto> queryListByParam(BranchStoreQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return branchSotreDao.queryListByParam(query);
    }


    @Override
    public Long insert(BranchStore entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        branchSotreDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(BranchStore entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        branchSotreDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(BranchStore param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return branchSotreDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(BranchStore param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return branchSotreDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return branchSotreDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return branchSotreDao.deleteByIdList(idList);
    }
}
